import {
  setPageTitleAndBgcolor,
  showAnimation,
  showFailModal,
  selectPhoto,
} from '../../../util/util'
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    systemConfig: {},
    aiMenu: [{
        name: '通用文字识别',
        languageKey: 'accurateBasic',
        icon: 'geneText',
        theme: 'light',
        bgcolor: '#99CCFF',
        isLock: false,
      },
      {
        name: '图片文字识别',
        languageKey: 'webImage',
        icon: 'imgText',
        theme: 'light',
        bgcolor: '#CCFF99',
        isLock: false,
      },
      {
        name: '手写文字识别',
        languageKey: 'handWriting',
        icon: 'handleText',
        theme: 'light',
        bgcolor: '#CCFFCC',
        isLock: false,
      },
      {
        name: '数字识别',
        languageKey: 'numbers',
        icon: 'number',
        theme: 'light',
        bgcolor: '#99CCCC',
        isLock: false,
      }, {
        name: '身份证识别',
        languageKey: 'idCard',
        icon: 'idCard',
        theme: 'light',
        bgcolor: '#FFFFCC',
        isLock: false,
      }, {
        name: '车牌号识别',
        languageKey: 'licensePlate',
        icon: 'numberPlate',
        theme: 'light',
        bgcolor: '#66CCFF',
        isLock: false,
      }, {
        name: '营业执照识别',
        languageKey: 'businessLicense',
        icon: 'business',
        theme: 'light',
        bgcolor: '#CCFFFF',
        isLock: false,
      }
    ],
    animation: { //菜单过渡动画
      animation0: '',
      animation1: '',
      animation2: '',
      animation3: '',
      animation4: '',
      animation5: '',
      animation6: '',
    },
    isShowCropper: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      systemConfig: app.globalData.systemConfig
    });
    console.log(this.data.systemConfig);
    setPageTitleAndBgcolor(this.data.systemConfig.languageObj.menu[2].ai, this.data.systemConfig.theme == 'dark' ? '#151515' : '#FFFFFF');
    this.setLanguage();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  // 国际化
  setLanguage() {
    let aiMenu = this.data.aiMenu;
    let language = this.data.systemConfig.languageObj;
    aiMenu.forEach((item, index) => {
      item.name = language.aiMenu[index][item.languageKey];
    });
    this.setData({
      aiMenu,
    });
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    showAnimation(this, this.data.aiMenu.length, 0, 350);
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    showAnimation(this, this.data.aiMenu.length, 0, 350);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //take photo
  takePhoto(val) {
    let type = val.currentTarget.dataset.type;
    selectPhoto().then(res => {
      wx.navigateTo({
        url: `/AI/pages/cropper/cropper?type=${type}&path=${res.tempFiles[0].tempFilePath}`,
        success:res =>{
          console.log('res',res) ;
        }
      })
    }).catch(err => {
      showFailModal(err);
    })
  }
})